package com.second.mapper;

import com.second.model.pojo.FOrdSeckill;
import org.apache.ibatis.annotations.Update;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Repository
@Transactional
public interface FOrdSeckillMapper extends JpaRepository<FOrdSeckill, Integer> {

    List<FOrdSeckill> findAllByStatus(Integer status);

    @Query(value = "update f_ord_seckill set num = num - 1 where id=? and num>0",nativeQuery = true)
    @Modifying
    @Transactional // 事务的注解
    int updateNum(Integer secId);

    @Query(value = "update f_ord_seckill set num = num + 1 where id=?",nativeQuery = true)
    @Modifying
    @Transactional // 事务的注解
    int backNum(Integer secId);
}
